using System;
using System.Collections.Generic;
using UnityEngine;

public class Player : CharacterBase
{
   public InVariable playerMana;
   private Player player;
   public int maxMana;
   public List<GameObject> enemys;
   public ObjectEventSO GetPlayerEvent;
   
   public CardManager cardManager;

   public int CurrentMana
   {
       get => playerMana.currentValue;
       set => playerMana.SetValue(value);
   }

   protected override void Awake()
   {
       base.Awake();
       player = GetComponent<Player>();
   }

   private void OnEnable()
   {
       if (cardManager.gameLevel == GameLevel.Primary)
       {
           InitPlayerStatus(10);
       }
       else if (cardManager.gameLevel == GameLevel.Intermdiate)
       {
           InitPlayerStatus(20);
       }
       else if (cardManager.gameLevel == GameLevel.Senior)
       {
           InitPlayerStatus( 30);
       }
       
       playerMana.maxValue = maxMana;
       //设置初始能量值
       CurrentMana = playerMana.maxValue; 
       
       GetPlayerEvent.RaisEvent(this,this);
       
       GetPlayer(this);
       
       StartMovePos();
       foreach (var enemy in GameObject.FindGameObjectsWithTag("Enemy"))
       {
           enemys.Add(enemy);
       }
   }

   protected override void Start()
   {
       base.Start();
       StartMovePos();
   }

   public void NewTurn()
   {
       CurrentMana = maxMana;
   }

   public void ReduceMana(int cost)
   {
       CurrentMana -= cost;
       if (CurrentMana <= 0)
           CurrentMana = 0;
   }
   public void AddMana(int cost)
   {
       CurrentMana += cost;
       if (CurrentMana <= 0)
           CurrentMana = 0;
   }

   public void NewGame()
   {
       currentHp = MaxHp;
       isDead = false;
       buffRound.currentValue = buffRound.maxValue;
       NewTurn();
   }

   public void InitPlayerStatus(int MP)
   {
       maxMana = MP;
   }
}
